<?php

namespace App\Services\User;

use App\Services\ProjectValidate;

/**
 * 当前模块验证规则集合
 *
 * Class ValidateUser
 */
class ValidateUser extends ProjectValidate {
    /**
     * 类初始化
     * @param array $initData
     * @return mixed
     */
    public function initValidate($initData = [])
    {
        // TODO: Implement initValidate() method.
        if (!empty($initData['status'])) {
            $this->rules['status']  = 'int:0,1,2';
        }
    }

    /**
     * @var array 验证规则集合
     */
    public $rules = [
        'id'                => 'int|min:1',
        'name'              => 'required|alpha_dash|min:5|max:16',
        'real_kname'          => 'alpha_dash|min:5|max:16',
        'login_password'    => 'alpha_dash|min:8|max:16',
        'old_login_password'=> 'alpha_dash|min:8|max:16',
        're_login_password' => 'alpha_dash|min:8|max:16|same:login_password',
        'pay_password'      => 'numeric|digits:6',
        'old_pay_password'  => 'numeric|digits:6',
        're_pay_password'   => 'numeric|digits:6|same:pay_password',
        'row_ids'           => 'regex:/^(\d)+(,\d+)*/',
        'row_group_ids'     => 'regex:/^(\d)+(,\d+)*/',
        'other_info'        => 'regex:/^{.*}$/',
        'ids'               => 'regex:/^\d+(,\d+)*$/',
        'role_id'           => 'int|min:1',
        'id_number'         => ['regex'=>'^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$'],
        'front_img'         => 'size:2',
        'back_img'          => 'size:2',
//        'real_name'         => 'size:2',
        'status'            => 'int:1,2',
        'auto_login_time'   => 'int|min:1',
        'auto_login_token'  => ['alpha_dash', 'size' => '32'],
        'is_auto_login'     => 'in:0,1',
        'is_add_no_user_counts' => 'in:0,1',
        'authen_status'     => 'int|in:-1,0,1,2',
        'email'   => 'email',
        'role_ids'  => 'required|int|min:1',
        'card' => 'size:18|unique:users_info,card',
        'band' => 'size:16',
        'phone'  => 'regex:/^1\d{10}/|size:11|unique:users_info,phone',
    ];

    /**
     * @var array 当前验证错误信息
     */
    public $messages = [
    ];

    /**
     * @var array 上面规则中定义的 key 的名字
     */
    public $attributes = [
        'id'   => 'ID',
        'card' =>'身份证',
        'band' =>'银行卡'
    ];

}